<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul id="ul"></ul>
    <script>
        let todoArr = ['eat', 'sleep', 'coding'];
        // 声明一个变量，content用来盛放字符串，字符串的内容决定了ul中的内容
        var content = '';
        // 循环，todoArr.length是数组的长度，也是循环的次数
        for (var index = 0; index < todoArr.length; index++) {
            // += 是累加，会保留上次的结果
            content += '<li>'+todoArr[index]+"<button onclick='del()'>del</button></li>";
        }
        // content是ul的好大儿，要放在ul中
        ul.innerHTML = content;

        function del () {
            console.log('del');
        }
    </script>
</body>
</html>